#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: title02最少数量线段覆盖.py 
@version:
@time: 2023/05/29

3
1,4
2,5
3,6


2
"""
from collections import defaultdict


def solve(n, points):
    line = defaultdict(int)

    for point in points:
        for i in range(point[0], point[1] + 1):
            line[i] += 1

    del_num = 0

    for point in points:
        deletable = True
        for i in range(point[0], point[1] + 1):
            if line[i] <= 1:
                deletable = False
                break
        if deletable:
            for i in range(point[0], point[1] + 1):
                line[i] -= 1
            del_num += 1
    return n - del_num


n = int(input())
points = [list(map(int, input().split(','))) for i in range(n)]
res = solve(n, points)
print(res)
